// SettingForm.h : Declaration of the CSettingForm

#pragma once

#include "resource.h"       // main symbols

#include <atlhost.h>
#include <string>

#include "../omsproxy/OMSClientBase.h"
//#include "OMSClientBase.h"

using namespace ATL;

// CSettingForm

class CSettingForm : 
	public CAxDialogImpl<CSettingForm>
{
private:
	OMSClientBase* m_client;
public:
	CSettingForm()
	{
		m_client = NULL;
	}

	~CSettingForm()
	{
		if(m_client)
			delete m_client;
	}

	enum { IDD = IDD_SETTINGFORM };

BEGIN_MSG_MAP(CSettingForm)
	MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog)
	COMMAND_HANDLER(IDOK, BN_CLICKED, OnClickedOK)
	COMMAND_HANDLER(IDCANCEL, BN_CLICKED, OnClickedCancel)
	CHAIN_MSG_MAP(CAxDialogImpl<CSettingForm>)
END_MSG_MAP()

// Handler prototypes:
//  LRESULT MessageHandler(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
//  LRESULT CommandHandler(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled);
//  LRESULT NotifyHandler(int idCtrl, LPNMHDR pnmh, BOOL& bHandled);

	LRESULT OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
	{
		CAxDialogImpl<CSettingForm>::OnInitDialog(uMsg, wParam, lParam, bHandled);
		bHandled = TRUE;
		return 1;  // Let the system set the focus
	}

	LRESULT OnClickedOK(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled);

	LRESULT OnClickedCancel(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
	{
		EndDialog(wID);
		return 0;
	}

private:
	//build a userinfo string to be sent to the webservice;
	LRESULT  BuildUserInfoInternal(const std::wstring& userName , const std::wstring& Password , std::wstring& result);
	//only check if the web service use ssl(begin with https)
	bool CheckURL(const std::wstring& url);
	//Get service info through gsoap client
	LRESULT TryGetServiceInfo(std::wstring& inputURL , std::wstring& resultServiceInfo);
	//parse service info and save into register, in the same time check if the serviceurl and url in serviceInfo is match
	/*
	register struct
	OutlookAddin.FormAddin
		serviceProvider				serviceProvider string
									serviceUri	string
									signUpPage	string
									localName	string
									SMS_maxRecipientsPerMessage 	DWORD
									SMS_maxMessagesPerSend		DWORD
									SMS_maxSbcsPerMessage		DWORD
									SMS_maxDbcsPerMessage 		DWORD	
									USER	string
									PWD		string
									MOBILE	string
									MAIL	string
						
	*/
	LRESULT ParseAndSaveServiceInfo(const std::wstring& serviceInfo, const std::wstring& serviceurl, std::wstring& serviceProvider);
	LRESULT ParseAndSaveUserInfo(const std::wstring& userInfo,const std::wstring& user, const std::wstring& pwd, const std::wstring& serviceProvider);
};


